import type { DictMap } from '@/types/common/dict'
import { getDictByTypeService } from '@/apis/dict'

export const useDictStore = defineStore('dict', () => {
  /**
   * 缓存字典数据
   */
  const dictMap = ref<DictMap>({})
  const getDictByType = async (dictType: string) => {
    if (dictMap.value[dictType]) return dictMap.value[dictType]
    const res = await getDictByTypeService(dictType)

    dictMap.value[dictType] = res || []
    return dictMap.value[dictType]
  }
  return {
    dictMap,
    getDictByType,
  }
})
